package com.c.ctgproject.ui.storage.material

import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseActivity
import com.c.ctgproject.entity.storage.StorageMaterialOutEntity
import com.c.ctgproject.mode.MyConstants
import com.c.ctgproject.utils.MyLog
import com.c.ctgproject.utils.handlerCall
import com.c.ctgproject.utils.showToast
import kotlinx.android.synthetic.main.activity_storage_material_out_detail.*

/**
 *作者:LiBW
 *创建日期: 2020/9/15
 *描述:仓储 物料出库详情 页面
 */
class StorageMaterialOutDetailActivity : BaseActivity() {
    private val entity: StorageMaterialOutEntity.DataBean.ListBean by lazy { intent.extras!!.get(MyConstants.ENTITY) as StorageMaterialOutEntity.DataBean.ListBean }

    private val mViewModel: StorageMaterialOutDetailViewModel by lazy { ViewModelProvider(this)[StorageMaterialOutDetailViewModel::class.java] }
    override fun getLayout() = R.layout.activity_storage_material_out_detail

    override fun event() {
        changeTransparentStatusBar()
        mOrderIdTV.text = entity.materialSalesNo.toString()
        mSellerNameTV.text = entity.userName.toString()
        mTimeTV.text = entity.auditTime.toString()
        mMaterialNameTV.text = entity.materialName.toString()
        mWeightTV.text = entity.materialInventoryWeight.toString()
        mCountTV.text = entity.materialInventoryNumber.toString()
        mApplyCountTV.text = entity.planSalesNumber.toString()
        mApplyWeightTV.text = entity.planSalesWeight.toString()
        mMarkTV.text = entity.remark.toString()

        mViewModel.confirmResult.observe(this, Observer {
            loading.dismiss()
            it.handlerCall({
                showToast("确认出库成功")
                finish()
            }, { msg ->
                showToast(msg)
            })

        })
        mViewModel.error.observe(this, Observer {
            loading.dismiss()
            MyLog.d("确认错误:$it")
            showToast(it)
        })


    }

    override fun click() {
        mCanOutBTN.setOnClickListener {
            mViewModel.confirm(entity.materialSalesOrderId.toString(), entity.materialId, entity.planSalesWeight.toInt(), entity.planSalesNumber)
        }
    }
}